﻿#include "T_CloseReportWarningWidget.h"
#include <iostream>
#include <QHBoxLayout>
#include <QIcon>
#include <QVBoxLayout>
#include <QLabel>
#include "ElaPushButton.h"
#include "ElaLineEdit.h"
#include "ElaComboBox.h"
#include "ElaScrollPageArea.h"
#include "ElaImageCard.h"
#include "ElaStatusBar.h"
#include "ElaMessageBar.h"
#include "ElaText.h"
#include "GenerateReportBase.h"
#include "MainWindow.h"
#include "CreateNewReport.h"
#include "CloseCurrentReport.h"
#include "GemerateFinalReport.h"
using namespace std;

namespace GenerateReport
{
    T_CloseReportWarningWidget::T_CloseReportWarningWidget(QWidget* parent)
        : ElaWidget(parent)
    {
        setWindowTitle(QStringLiteral("警告"));
        setWindowIcon(QIcon(":/include/Image/Moon.jpg"));
        //setStyleSheet("QWidget { qproperty - windowTitleFontSize: 14px; }");
        this->setIsFixedSize(true);
        setWindowModality(Qt::ApplicationModal);
        setWindowButtonFlags(ElaAppBarType::CloseButtonHint);

        //总布局（纵）
        QVBoxLayout* mainLayout = new QVBoxLayout(this);

        //第一行布局（横）
        QHBoxLayout* firstRowLayout = new QHBoxLayout;
        //第二行布局（横）
        QHBoxLayout* secondRowLayout = new QHBoxLayout;

        //第一行内容：报告名称设置
        ElaText* reportNameText = new ElaText(QStringLiteral("报告未保存，是否需要生成报告？"), this);
        reportNameText->setWordWrap(false);
        reportNameText->setTextPixelSize(14);
        firstRowLayout->addWidget(reportNameText);
        firstRowLayout->setAlignment(Qt::AlignHCenter);
        //QFont font = page1->font();
        //font.setPixelSize(32);


        //第三行内容：确定、取消按钮
        ElaPushButton* cancelButton = new ElaPushButton(QStringLiteral("否"), this);
        cancelButton->setFixedWidth(80);
        ElaPushButton* confirmButton = new ElaPushButton(QStringLiteral("是"), this);
        confirmButton->setFixedWidth(80);
        secondRowLayout->addWidget(cancelButton);
        secondRowLayout->addWidget(confirmButton);
        secondRowLayout->setAlignment(Qt::AlignRight);
        secondRowLayout->setSpacing(2);

        //总体布局
        //mainLayout->setContentsMargins(0, 0, 0, 0);
        mainLayout->addLayout(firstRowLayout);
        mainLayout->addLayout(secondRowLayout);

        //接口

        connect(cancelButton, &ElaPushButton::clicked, this, &T_CloseReportWarningWidget::slot_cancelButtonClicked);

        connect(confirmButton, &ElaPushButton::clicked, this, &T_CloseReportWarningWidget::slot_confirmButtonClicked);

    }

    T_CloseReportWarningWidget::~T_CloseReportWarningWidget()
    {
    }

    //如果点击确定删除则直接关闭
    //如果点击取消则关闭弹窗，并跳转到生成报告窗口
    void T_CloseReportWarningWidget::slot_cancelButtonClicked()
    {
        //关闭窗口
        ElaWidget::close();
        GenerateReport::CloseCurrentReport _crr;
        _crr.closeReportExcute();
    }

    void T_CloseReportWarningWidget::slot_confirmButtonClicked()
    {
        ElaWidget::close();
        auto _currentReportNum = GenerateReportBaseInstance->getCurrentReportNumber();
        if (_currentReportNum == 0)
        {
            auto _mainWindow = GenerateReportBaseInstance->getMainWindow();
            //_mainWindow->statusBarPromptInformation(QString("当前没有正在编辑的报告，请先新建一份报告！"));
            auto _msg = QStringLiteral("当前没有正在编辑的报告，请先新建一份报告！");
            ElaMessageBar::warning(ElaMessageBarType::PositionPolicy::Top, QStringLiteral("警告"), _msg, 3000, this);
            return;
        }
        GenerateReport::GemerateFinalReport gfp;
        gfp.actionSlot_GemerateFinalReport();
    }
}
